<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">

      <el-form-item label="申请人" prop="username" label-width="150px">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入申请人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="部门" prop="deptName" label-width="100px">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="姓名" prop="staffName" label-width="100px">
        <el-input
          v-model="queryParams.staffName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item style="margin-left: 20px">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['module:adjustment:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['module:adjustment:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['module:adjustment:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['module:adjustment:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>

    <el-table :border="true" v-loading="loading" :data="adjustmentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column type="index" width="55" align="center" label="序号" />
      <el-table-column label="单号" align="center" width="150px"  prop="serialNum" v-if="columns[9].visible"/>
      <el-table-column label="申请人" width="150px" align="center" prop="username" v-if="columns[0].visible"/>
      <el-table-column label="部门" align="center" prop="deptName" v-if="columns[1].visible"/>
      <el-table-column label="现职位" align="center" prop="position" v-if="columns[2].visible"/>
      <el-table-column label="姓名" align="center" prop="staffName" v-if="columns[3].visible"/>
      <el-table-column label="目标职位" align="center" prop="targetPosition" v-if="columns[4].visible"/>
      <el-table-column label="目标薪资" align="center" prop="targetSalary" v-if="columns[5].visible"/>
      <el-table-column label="理由" align="center" prop="applicationReason" v-if="columns[6].visible"/>
      <el-table-column label="状态" align="center" prop="businessStatus"  v-if="columns[10].visible">
        <template slot-scope="scope">
          <div v-if="scope.row.businessStatus=='completed'">已完成</div>
          <div v-if="scope.row.businessStatus=='approve'">审批中</div>
          <div v-if="scope.row.businessStatus=='reject'">驳回</div>
          <div v-if="scope.row.businessStatus=='pending'">待审批</div>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" width="150px" prop="remark" v-if="columns[7].visible"/>
      <el-table-column label="审批进度" fixed="right" width="150px" align="center" v-if="columns[8].visible">
        <template slot-scope="scope">
          <el-button type="text" @click="openApprover(scope.row)">查看进度</el-button>
        </template>
      </el-table-column>
      <el-table-column label="撤回/再次提交" fixed="right"  width="150px" style="">
        <template slot-scope="scope">
          <el-button  type="text" style="color:red" @click="recallFn(scope.row)">撤回</el-button>
          <el-button v-if="scope.row.businessStatus==='reject' || scope.row.businessStatus==='recall'" type="text" style="color:limegreen"  @click="readdFn(scope.row)">再次提交</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" width="150px" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['module:adjustment:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            style="color:red"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['module:adjustment:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改职位，薪资申请单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body @close="cancel">
      <el-form ref="form" :model="form" :rules="rules" :inline="false" label-width="180px">
          <el-form-item style="width: 400px" label="申请人" prop="username">
            <el-input :disabled=true v-model="form.username" placeholder="请输入申请人"/>
          </el-form-item>

          <el-form-item  style="width: 400px;;" label="归属部门" prop="deptId">
            <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门"/>
          </el-form-item>


        <el-form-item style="width: 400px" label="现职位" prop="position">
          <el-select v-model="form.position" placeholder="请选择">
            <el-option
              v-for="item in postOptions"
              :key="item.postId"
              :label="item.postName"
              :value="item.postId">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item  style="width: 400px" label="姓名" prop="staffName">
<!--          <Elselect :list="staffList" @fous="fousfn" v-model="form.staffName"></Elselect>-->
          <el-input style="width: 200px" v-model="form.staffName" readonly placeholder="请输入协同人名称">
            <template slot="append">
              <el-button type="primary" @click="openImportUser2">
                选择员工
              </el-button>
            </template>
          </el-input>

        </el-form-item>

        <el-form-item  style="width: 400px" label="目标职位" prop="targetPosition">
          <el-select v-model="form.targetPosition" placeholder="请选择">
            <el-option
              v-for="item in postOptions"
              :key="item.postId"
              :label="item.postName"
              :value="item.postId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item  style="width: 400px" label="目标薪资" prop="targetSalary">
          <el-input v-model="form.targetSalary" placeholder="请输入目标薪资"/>
        </el-form-item>
        <el-form-item  style="width: 400px" label="理由" prop="applicationReason">
          <el-input type="textarea" v-model="form.applicationReason" style="width: 220px" maxlength="200"
                    show-word-limit
                    placeholder="请输入理由"/>
        </el-form-item>
<!--        ____________________________-->
        <el-form-item label="是否使用流程模板" prop="typeStatus">
          <el-select v-model="form.typeStatus" placeholder="请选择"   @change="changeValue">
            <el-option

              v-for="item in ynOptions"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item  style="width: 400px" label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" style="width: 220px" maxlength="200" show-word-limit
                    placeholder="请输入内容"/>
        </el-form-item>


        <!-- 固定类型-->
        <div   v-if="showApproval2">
          <div style="margin-left: 100px"> 审批人：</div>
          <el-steps :active="0" align-center>
            <el-step v-for="(item,index) in approvalOptions" :key="index" :title="item.nickName" description="就不批"></el-step>
          </el-steps>
          <div style="margin-left: 100px">抄送人:</div>
          <div style="margin-left: 200px" >

            <el-avatar v-for="(item,index) in copyerOptions" :key="index"> {{item.userName}} </el-avatar>

          </div>
        </div>
        <!--自定义-->
        <div v-if="showApproval3">
          <div style="margin-left: 30px">
            <span>请选择审批人</span>
            <el-select @change="changeuseroptions" v-model="value1" multiple placeholder="请选择">
              <el-option
                v-for="item in userlistoptions"
                :key="item.userId"
                :label="item.userName"
                :value="item.userId">
              </el-option>
            </el-select>
<!--            <el-input v-model="approver.userName" style="width: 300px">-->
<!--              <template slot="append">-->
<!--                <el-button type="primary"  @click="openUser(1)">-->
<!--                  选择审批人-->
<!--                </el-button>-->
<!--              </template>-->
<!--            </el-input>-->
          </div>
          <div style="margin-left: 30px;margin-top: 10px">
            <span style="margin-right: 5px">请选择抄送人</span>
            <el-input v-model="copyer.userName" style="width: 300px">
              <template slot="append">
                <el-button type="primary"  @click="openUser(2)">
                  选择抄送人
                </el-button>
              </template>
            </el-input>
          </div>

        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 进度弹框-->

    <el-dialog   title="查看进度"   :visible.sync="showApprove" width="60%" append-to-body @close="close">

      <el-steps :active="active" align-center>
        <el-step v-for="item in approvalOptions" :title="item.approverName" :description="item.remark?item.remark:item.deferredRemark"></el-step>
      </el-steps>
      <div style="margin-left: 200px">
        <div v-for="item in copyerOptions" style="position: relative;width: 60px ;display: inline-block">
          <el-avatar style="color: #FFFFFF;background-color: cornflowerblue;"> {{item.copyerName }} </el-avatar>
          <i v-if="item.copyerStatus==='1'" class="el-icon-success"  style="position: absolute;right: 15px;top: 1px;color: limegreen"></i>
        </div>

      </div>

      <div v-if="butonShow" style="width: 500px;margin-left: 270px;margin-top: 50px" >
        <el-button style="display: inline-block"  icon="el-icon-check" type="success" sizi="mini" @click="textShow=true">通过</el-button>
        <el-button style="display: inline-block"  icon="el-icon-close" type="danger" sizi="mini" @click="textNOShow=true">驳回</el-button>
        <el-button style="display: inline-block"  icon="el-icon-loading" type="warning" sizi="mini" @click="deferredShow=true">延迟处理</el-button>

      </div>
    </el-dialog>
    <!--    审批意见框-->
    <el-dialog title="审批意见" :visible.sync="textShow" width="60%" append-to-body >
      <el-input style="width: 80%;height: 200px" type="textarea" placeholder="请填写审批意见" v-model="textArea"></el-input>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="approvalFn">确 定</el-button>
        <el-button @click="textClear">取 消</el-button>
      </div>
    </el-dialog>
    <!--    驳回-->
    <el-dialog title="驳回原因" :visible.sync="textNOShow" width="60%" append-to-body>
      <el-input style="width: 80%;height: 200px" type="textarea" placeholder="请填写审批意见" v-model="textArea"></el-input>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="approvalNoFn">确 定</el-button>
        <el-button @click="textClear">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="延迟原因" :visible.sync="deferredShow" width="60%" append-to-body>
      <el-input style="width: 80%;height: 200px" type="textarea" placeholder="延迟原因" v-model="deferredRemark"></el-input>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="deferredNoFn">确 定</el-button>
        <el-button @click="deferredClear">取 消</el-button>
      </div>
    </el-dialog>
    <import-user ref="user" @showUser="showUser"></import-user>

    <Elselect @meiye="myfn" @anme="anmefn" @chongzhi="czfn" @serch="serchfn" @dangqian="dqfn" ref="import" :list="staffList" ></Elselect>

  </div>

</template>

<script>
import {listAdjustment, getAdjustment, delAdjustment, addAdjustment, updateAdjustment} from "@/api/module/adjustment";
import {deptTreeSelect, getuserList,getuserrank} from "@/api/system/user";
import {listStaff} from "@/api/module/staff";
import Elselect from "@/components/ELselect/Elselect";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {getDicts} from "@/api/system/dict/data";
import {listType} from "@/api/module/type";
import importUser from '@/views/dialog/user.vue';
import { listRecord, getRecord, delRecord, addRecord, updateRecord } from "@/api/module/record";
import { listSubscribepattern, getSubscribepattern, delSubscribepattern, addSubscribepattern, updateSubscribepattern } from "@/api/module/subscribepattern";
import {copyrecodUpdata,listCopy} from '@/api/module/copy'

import {listPost} from '@/api/system/post'
import {addLeave, updateLeave} from "@/api/module/leave";
export default {
  name: "Adjustment",
  components: {
    Elselect,
    Treeselect,
     importUser
  },
  data() {
    return {
      deptOptions: undefined,// 部门树选项
      deptName: undefined,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 职位，薪资申请单表格数据
      adjustmentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        username: null,
        deptId: null,
        deptName: null,
        postId: null,
        position: null,
        staffId: null,
        staffName: null,
        targetPostId: null,
        targetPosition: null,
        targetSalary: null,
        applicationReason: null,
        status: null,
        tenantId: null,
      },
      // 表单参数
      form: {},
      // 列信息
      columns: [
        { key: 0, label: `申请人`, visible: true },
        { key: 1, label: `部门`, visible: true },
        { key: 2, label: `现职位`, visible: true },
        { key: 3, label: `姓名`, visible: true },
        { key: 4, label: `目标职位`, visible: true },
        { key: 5, label: `目标薪资`, visible: true },
        { key: 6, label: `理由`, visible: true },
        { key: 7, label: `备注`, visible: true },
        { key: 8, label: `审批进度`, visible: true },
        { key:9,label:'单号',visible: true},
        { key:10,label:'状态',visible: true},

      ],
      // 表单校验
      rules: {
        username: [{required: true, message: '请输入申请人姓名', trigger: 'blur'}],
        deptName: [{required: true, message: '请输入部门', trigger: 'blur'}],
        position: [{required: true, message: '请输入现职位', trigger: 'blur'}],
        staffName: [{required: true, message: '请输入姓名', trigger: 'blur'}],
        targetPosition: [{required: true, message: '请输入目标职位', trigger: 'blur'}],
        targetSalary: [{required: true, message: '请输入目标薪资', trigger: 'blur'}],
        applicationReason: [{required: true, message: '请输入理由', trigger: 'blur'}],
      },
      staffList: [],// 名字组件传参
      //_______
      ynOptions:[],//是否
      approvalOptions:[],

      showApprove:false,
      showApproval2:false,
      showApproval3:false,
      approver:{},//自定义审批人
      copyer:{},
      copyerOptions:[],
      listItem:{},//保存当前点击数据
      textShow:false,//意见弹框
      textNOShow:false,
      textArea:'',
      active:0,//进度条
      butonShow:false,
    //  ___
      postOptions:[],//岗位信息
      deferredRemark:'',//延迟原因
      deferredShow:false,
      value1:[],
      userlistoptions:[]
    };
  },
  watch: {

    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    this.getDeptTree()
    this.getPostlistOPtions()
    this.getList();

    this.getYesNo()
   this.getPostlistOPtions()
    this.getrankuser()
  },
  methods: {
    // 查询主管级别用户
    getrankuser(){
      getuserrank({rank:"主管",pageSize:1000}).then(res=>{
        this.userlistoptions=res.rows
      })
    },
    changeuseroptions(val){
      this.form.approverName=null
      val.forEach(ids=>{
        this.userlistoptions.forEach(item=>{
          if(ids==item.userId){
            if(this.form.approverName==null){
              this.form.approverName=item.userName
            }else {
              this.form.approverName= this.form.approverName+','+item.userName
            }
          }
        })
      })
    },
    // 延迟处理
    async  deferredNoFn(){
      await updateRecord({
        typeOperation: "deferred",
        serialNum :this.listItem.serialNum,
        deferredRemark:this.deferredRemark,
      })
      this.deferredShow=false
      this.$message.success('操作成功')
      this.butonShow=false
      await  this.openApprover()

    },
    deferredClear(){
      this.deferredShow=false
      this.deferredRemark=''
    },
    close(){
      this.butonShow=false
    },
    //撤回
    async recallFn(val){
      await updateRecord({
        typeOperation: "recall",
        serialNum :val.serialNum,
      })
      this.$message.success('撤回成功，可在修改后再次提交')
      await this.getList();
    },
    async getPostlistOPtions(){
      let res=await listPost()
      this.postOptions=res.rows
      console.log(this.postOptions)
    },
    //__________流程_____________________________

    //是或否
    getYesNo(){
      getDicts('yesorno').then(res=>{
        this.ynOptions=res.data
      })
    },
    //流程----------------------------------------------------------------
    //流程----------------------------------------------------------------
    async changeValue(val){
      console.log(val)
      if(val=='0'){
        //进度条展示
        this.showApproval3=false
        this.showApproval2=false
        this.value1 = []
        this.copyer = {}

      }else {
        //  自定义类型
        this.showApproval2=false
        this.showApproval3=true

      }
    },
    //打开用户
    openUser(val){
      this.$refs.user.show(val,1)
    },
    showUser(data){
      console.log(data)
      if(data.type=='1'){
        this.approver=data

        //自定义类型赋值
        this.form.approver=data.userId
        this.form.approverName=data.userName
      }
      if(data.type=='2'){
        this.copyer=data
        this.form.copyerId=data.userId
        this.form.copyerName=data.userName
      }

    },
    async openApprover(val){
      this.showApprove=true
      //保存当前数据
      this.listItem=val
      this.active=parseFloat(this.listItem.status)
      // 查询审批记录
      let res=await listRecord({serialNum:val.serialNum})
      var arr=res.rows


      for(var i=0;i<arr.length;i++){
        for(var j=i+1;j<arr.length;j++){
          //如果第一个比第二个大，就交换他们两个位置
          if( arr[i].sequence>arr[j].sequence){
            var temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
          }
        }
      }
      arr.forEach(item=>{
        if(item.approvalStatus=='completed'){
          this.active++
        }
      })
      this.approvalOptions=arr
      //判断按钮是否显示
      this.approvalOptions.forEach(item=>{
        if(item.approvalStatus=='approve'){

          if(this.$store.getters.id===item.approverId){

            this.butonShow=true
          }
        }
      })
      //  查询抄送详情
      let res2=await listCopy({serialNum:val.serialNum})
      this.copyerOptions=res2.rows

    },
    //审批意见框关闭事件
    textClear(){
      this.textArea=''
      this.textShow=false
      this.textNOShow=false
    },
    //根据对应审批，获取相应的申请类型————————————————————————————------------
    async getapproverTpye(){
      let res =await getSubscribepattern(2)
      this.form.subscribePatternName=res.data.patternName
      this.form.subscribePatternId=res.data.id
    },
    //审批判断
    async approvalFn(){

      await updateRecord({
        typeOperation: "agree",
        serialNum :this.listItem.serialNum,
        remark:this.textArea,
      })
      //审批意见框关闭
      this.textShow=false
      await this.$message.success('审批成功')
      this.butonShow=false
      await  this.openApprover()


    },

    async approvalNoFn(){
      await updateRecord({
        typeOperation: "rejected",
        serialNum :this.listItem.serialNum,
        remark:this.textArea,
      })
      //审批意见框关闭
      this.textNOShow=false
      await this.$message.success('驳回成功')
      this.butonShow=false
      await  this.openApprover()
    },
    //_____________________________
    fousfn(val) {
      this.form.staffName = val
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptOptions = response.data;
        console.log(response.data)
      });
    },

    /** 查询职位，薪资申请单列表 */
    getList() {
      this.loading = true;
      this.queryParams.userId=this.$store.getters.id;
      listAdjustment(this.queryParams).then(response => {
        this.adjustmentList = response.rows;
        let arr=this.adjustmentList
        arr.forEach(item=>{
          item.postId=item.position
          item.position=this.getValue(this.postOptions,item.postId)
          item.targetPostId=item.targetPosition
          item.targetPosition=this.getValue(this.postOptions,item.targetPostId)
          item.deptName=this.getdeptName(this.deptOptions,item)


        })
        this.adjustmentList=arr
        console.log(this.adjustmentList)
        this.total = response.total;
        this.loading = false;
      });
    },

    getValue(arr, item) {
      for (let i = 0; i < arr.length; i++) {
        if (item == arr[i].postId) {
          return arr[i].postName
        }
      }
    },
    //查询对应部门
    getdeptName(arr,item){
      for (let i = 0; i < arr.length; i++) {
        if (item.deptId == arr[i].id) {
          return arr[i].label
        }
        if(arr[i].children){
          console.log('11')
          return this.getdeptName(arr[i].children,item)
        }
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.approver={}
      this.copyer={}
      this.approvalOptions=[]
      this.copyerOptions=[]
      this.reset();
    },
    // 表单重置
    reset() {
      this.queryParams={}
      this.value1 = []
      this.copyer = {}
      this.form = {
        adjustmentId: null,
        userId: null,
        username: null,
        deptId: null,
        deptName: null,
        postId: null,
        position: null,
        staffId: null,
        staffName: null,
        targetPostId: null,
        targetPosition: null,
        targetSalary: null,
        applicationReason: null,
        status: null,
        tenantId: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        typeStatus:'0',
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.adjustmentId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    async handleAdd() {
      this.reset();
      this.form.delFlag = 0//0代表存在 2代表删除
      //获取基础信息
      this.form.username = this.$store.getters.name
      this.form.userId=this.$store.getters.id
      this.form.staffId=this.$store.getters.staffId
      this.form.staffName=this.$store.getters.staffName
      // await this.getapproverTpye()//------------------------------------------
      const res = await listStaff(this.queryParams)
      this.staffList = res.rows
      this.open = true;
      this.title = "添加职位，薪资申请单";
      this.$refs.import.unit =res.total
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const adjustmentId = row.adjustmentId || this.ids
      getAdjustment(adjustmentId).then(response => {
        this.form = response.data;
        if (this.form.typeStatus == '1'){
          this.showApproval3=true;
          let array=this.form.approver.split(',')
          array.forEach(item=>{
            this.value1.push(Number(item))
          })
          this.copyer.userName=this.form.copyerName
        }
        this.open = true;
        this.title = "修改职位，薪资申请单";
      });
    },
    readdFn(val){
      this.open=true
      this.form=val
      if(val.businessStatus==="recall" || val.businessStatus==="reject"){
        this.title="重新填写信息"
      }

    },
    /** 提交按钮 */
    submitForm() {
      this.form.approver=this.value1.join(',')
      this.$refs["form"].validate(valid => {
        if (valid) {
          //主动撤回，重新提交
          if(this.form.id && this.form.businessStatus==='recall'){
            addAdjustment(this.form).then(response => {
              this.$modal.msgSuccess("重新提交成功");
              this.open = false;
              this.getList();
            });//驳回提交
          }else if(this.form.id && this.form.businessStatus==='reject'){
            this.form.serialNum=''
            addAdjustment(this.form).then(response => {
              this.$modal.msgSuccess("重新提交成功");
              this.open = false;
              this.getList();
            });//修改提交
          }else if(this.form.id){
            updateAdjustment(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });//新增提交
          }else{
            addAdjustment(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const adjustmentIds = row.adjustmentId || this.ids;
      this.$modal.confirm('是否确认删除职位，薪资申请单编号为"' + adjustmentIds + '"的数据项？').then(function () {
        return delAdjustment(adjustmentIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('module/adjustment/export', {
        ...this.queryParams
      }, `adjustment_${new Date().getTime()}.xlsx`)
    },
    //组件
    openImportUser2() {
      this.$refs.import.show();
    },
    async myfn(val){
      console.log(val)
      this.queryParams.pageSize=val
      const res = await listStaff(this.queryParams)
      // console.log(res.rows)
      this.staffList=res.rows
    },
    async dqfn(val){
      this.queryParams.pageNum=val
      const res = await listStaff(this.queryParams)
      // console.log(res.rows)
      this.staffList=res.rows
    },
    //组件搜索功能
    async serchfn(val){
      this.queryParams.name=val
      const res = await listStaff(this.queryParams)
      this.staffList=res.rows
    },
    //组件重置功能
    async czfn(){
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        username: null,
        trainingItems: null,
        sponsor: null,
        sponsorDept: null,
        participant: null,
        participantDept: null,
        initiateTime: null,
        startTime: null,
        endTime: null,
        days: null,
        status: null,
        tenantId: null,
        staffId: null,
        staffName: null,
      }
      const res = await listStaff(this.queryParams)
      this.staffList=res.rows
      this.listDatafn()
    },
    anmefn(val){
      this.form.staffName=val.name
      this.form.staffId=val.id
      this.$refs.import.visible=false
    }
  }
};
</script>
